<!DOCTYPE html>
<html>
<head>
    <title>Physics Diagram - Rope Initial State</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        canvas {
            border: 1px solid #d9d9d9;
        }
    </style>
</head>
<body>

<canvas id="physicsCanvas" width="450" height="550"></canvas>

<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // --- Style and Coordinate Settings ---
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    const centerX = canvas.width / 2;

    // --- Draw Ceiling ---
    const ceilingY = 100;
    const ceilingWidth = 300;
    const ceilingStartX = centerX - ceilingWidth / 2;
    const ceilingEndX = centerX + ceilingWidth / 2;
    
    ctx.lineWidth = 2;
    ctx.beginPath();
    ctx.moveTo(ceilingStartX, ceilingY);
    ctx.lineTo(ceilingEndX, ceilingY);
    ctx.stroke();

    // Draw hatching for the ceiling
    ctx.lineWidth = 1.5;
    const hatchSpacing = 20;
    const hatchLength = 20;
    for (let i = ceilingStartX + hatchSpacing; i <= ceilingEndX + hatchSpacing; i += hatchSpacing) {
        ctx.beginPath();
        ctx.moveTo(i, ceilingY);
        ctx.lineTo(i - hatchLength, ceilingY - hatchLength);
        ctx.stroke();
    }
    
    // --- Draw the Rope ---
    ctx.lineWidth = 4;
    ctx.lineCap = 'round';
    
    const ropeSpacing = 120;
    const ropeTopA_X = centerX - ropeSpacing / 2;
    const ropeTopB_X = centerX + ropeSpacing / 2;
    const ropeSideLength = 180;
    const ropeBottomY = ceilingY + ropeSideLength;
    const arcRadius = ropeSpacing / 2;
    const arcCenterX = centerX;

    ctx.beginPath();
    // Left side of the rope
    ctx.moveTo(ropeTopA_X, ceilingY);
    ctx.lineTo(ropeTopA_X, ropeBottomY);
    // U-bend
    ctx.arc(arcCenterX, ropeBottomY, arcRadius, Math.PI, 0, false);
    // Right side of the rope
    ctx.lineTo(ropeTopB_X, ceilingY);
    ctx.stroke();

    // --- Draw Labels ---
    
    // Labels 'A' and 'B'
    ctx.font = 'italic 36px "Times New Roman"';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    ctx.fillText('A', ropeTopA_X - 40, ceilingY + 50);
    ctx.fillText('B', ropeTopB_X + 40, ceilingY + 50);
    
    // Helper function to draw the L/2 fraction
    function drawFraction(x, y) {
        // Draw 'L'
        ctx.font = 'italic 36px "Times New Roman"';
        ctx.textBaseline = 'bottom';
        ctx.fillText('L', x, y);

        // Draw fraction line
        ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(x - 20, y + 4);
        ctx.lineTo(x + 20, y + 4);
        ctx.stroke();
        
        // Draw '2'
        ctx.font = '36px "Times New Roman"';
        ctx.textBaseline = 'top';
        ctx.fillText('2', x, y + 6);
    }
    
    const labelVerticalCenter = ceilingY + ropeSideLength / 2;
    
    // Draw left L/2
    const labelLeftX = ropeTopA_X - 60;
    drawFraction(labelLeftX, labelVerticalCenter);
    
    // Draw right L/2
    const labelRightX = ropeTopB_X + 60;
    drawFraction(labelRightX, labelVerticalCenter);
    
    // Draw "图 1" (Figure 1)
    ctx.font = '32px "SimSun", "STSong", serif';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    ctx.fillText('图 1', centerX, ropeBottomY + arcRadius + 80);

</script>

</body>
</html>